home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 44 / PC Actual CD 44.iso / Linux / Cygwin / full.exe / Disk1 / data1.cab / Tools / share / tix4.1 / SListBox.tcl < prev    next >
Encoding:
Text File  |  1998-12-04  |  7.1 KB  |  305 lines

  1. # SListBox.tcl --
  2. #
  3. #    This file implements Scrolled Listbox widgets
  4. #
  5. # Copyright (c) 1996, Expert Interface Technologies
  6. #
  7. # See the file "license.terms" for information on usage and redistribution
  8. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  9. #
  10.  
  11.  
  12. # ToDo:
  13. # -anchor (none)
  14. #
  15.  
  16. tixWidgetClass tixScrolledListBox {
  17.     -classname TixScrolledListBox
  18.     -superclass tixScrolledWidget
  19.     -method {
  20.     }
  21.     -flag {
  22.     -anchor -browsecmd -command -state
  23.     }
  24.     -static {
  25.     -anchor
  26.     }
  27.     -configspec {
  28.     {-anchor anchor Anchor w}
  29.     {-browsecmd browseCmd BrowseCmd ""}
  30.     {-command command Command ""}
  31.     {-state state State normal}
  32.     {-takefocus takeFocus TakeFocus 1 tixVerifyBoolean}
  33.     }
  34.     -default {
  35.     {.scrollbar            auto}
  36.     {*borderWidth            1}
  37.     {*listbox.highlightBackground    #d9d9d9}
  38.     {*listbox.relief        sunken}
  39.     {*listbox.background        #c3c3c3}
  40.     {*listbox.takeFocus        1}
  41.     {*Scrollbar.background        #d9d9d9}
  42.     {*Scrollbar.troughColor        #c3c3c3}
  43.     {*Scrollbar.takeFocus        0}
  44.     {*Scrollbar.relief        sunken}
  45.     {*Scrollbar.width        15}
  46.     }
  47. }
  48.  
  49. proc tixScrolledListBox:InitWidgetRec {w} {
  50.     upvar #0 $w data
  51.  
  52.     tixChainMethod $w InitWidgetRec
  53.  
  54.     set data(x-first) 0
  55.     set data(x-last)  1
  56.     set data(y-first) 0
  57.     set data(y-last)  1
  58. }
  59.  
  60. proc tixScrolledListBox:ConstructWidget {w} {
  61.     upvar #0 $w data
  62.     global tcl_platform
  63.  
  64.     tixChainMethod $w ConstructWidget
  65.  
  66.     set data(w:listbox) \
  67.     [listbox $w.listbox]
  68.     set data(w:hsb) \
  69.     [scrollbar $w.hsb -orient horizontal]
  70.     set data(w:vsb) \
  71.     [scrollbar $w.vsb -orient vertical ]
  72.  
  73.     if {$data(-sizebox) && $tcl_platform(platform) == "windows"} {
  74.         set data(w:sizebox) [ide_sizebox $w.sizebox]
  75.     }
  76.  
  77.     set data(pw:client) $data(w:listbox)
  78. }
  79.  
  80. proc tixScrolledListBox:SetBindings {w} {
  81.     upvar #0 $w data
  82.  
  83.     tixChainMethod $w SetBindings
  84.  
  85.     $data(w:listbox) config \
  86.     -xscrollcommand "tixScrolledListBox:XView $w"\
  87.     -yscrollcommand "tixScrolledListBox:YView $w"
  88.  
  89.     $data(w:hsb) config -command "$data(w:listbox) xview"
  90.     $data(w:vsb) config -command "$data(w:listbox) yview"
  91.  
  92.     bind $w <Configure> "+tixScrolledListBox:Configure $w"
  93.     bind $w <FocusIn> "focus $data(w:listbox)"
  94.  
  95.     bindtags $data(w:listbox) \
  96.     "$data(w:listbox) TixListboxState Listbox TixListbox [winfo toplevel $data(w:listbox)] all"
  97.     tixSetMegaWidget $data(w:listbox) $w
  98. }
  99.  
  100. proc tixScrolledListBoxBind {} {
  101.     tixBind TixListboxState <1> {
  102.     if {[set [tixGetMegaWidget %W](-state)] == "disabled"} {
  103.         break
  104.     }
  105.     }
  106.     tixBind TixListbox      <1> {
  107.     if [tixGetBoolean -nocomplain [%W cget -takefocus]] {
  108.         focus %W
  109.     }
  110.     tixScrolledListBox:Browse [tixGetMegaWidget %W]
  111.     }
  112.  
  113.     tixBind TixListboxState <B1-Motion> {
  114.     if {[set [tixGetMegaWidget %W](-state)] == "disabled"} {
  115.         break
  116.     }
  117.     }
  118.     tixBind TixListbox      <B1-Motion> {
  119.     tixScrolledListBox:Browse [tixGetMegaWidget %W]
  120.     }
  121.  
  122.     tixBind TixListboxState <Up> {
  123.     if {[set [tixGetMegaWidget %W](-state)] == "disabled"} {
  124.         break
  125.     }
  126.     }
  127.     tixBind TixListbox      <Up> {
  128.     tixScrolledListBox:KeyBrowse [tixGetMegaWidget %W]
  129.     }
  130.  
  131.     tixBind TixListboxState <Down> {
  132.     if {[set [tixGetMegaWidget %W](-state)] == "disabled"} {
  133.         break
  134.     }
  135.     }
  136.     tixBind TixListbox      <Down> {
  137.     tixScrolledListBox:KeyBrowse [tixGetMegaWidget %W]
  138.     }
  139.  
  140.     tixBind TixListboxState <Return> {
  141.     if {[set [tixGetMegaWidget %W](-state)] == "disabled"} {
  142.         break
  143.     }
  144.     }
  145.     tixBind TixListbox      <Return> {
  146.     tixScrolledListBox:KeyInvoke [tixGetMegaWidget %W]
  147.     }
  148.  
  149.  
  150.     tixBind TixListboxState <Double-1> {
  151.     if {[set [tixGetMegaWidget %W](-state)] == "disabled"} {
  152.         break
  153.     }
  154.     }
  155.     tixBind TixListbox      <Double-1> {
  156.     tixScrolledListBox:Invoke [tixGetMegaWidget %W]
  157.     }
  158.  
  159.     tixBind TixListboxState <ButtonRelease-1> {
  160.     if {[set [tixGetMegaWidget %W](-state)] == "disabled"} {
  161.         break
  162.     }
  163.     }
  164.     tixBind TixListbox      <ButtonRelease-1> {
  165.     tixScrolledListBox:Browse [tixGetMegaWidget %W]
  166.     }
  167. }
  168.  
  169. proc tixScrolledListBox:Browse {w} {
  170.     upvar #0 $w data
  171.  
  172.     if {$data(-browsecmd) != ""} {
  173.     set bind(specs) {%V}
  174.     set bind(%V) [$data(w:listbox) get \
  175.         [$data(w:listbox) nearest [tixEvent flag y]]]
  176.     tixEvalCmdBinding $w $data(-browsecmd) bind
  177.     }
  178. }
  179.  
  180. proc tixScrolledListBox:KeyBrowse {w} {
  181.     upvar #0 $w data
  182.  
  183.     if {$data(-browsecmd) != ""} {
  184.     set bind(specs) {%V}
  185.     set bind(%V) [$data(w:listbox) get active]
  186.     tixEvalCmdBinding $w $data(-browsecmd) bind
  187.     }
  188. }
  189.  
  190. # tixScrolledListBox:Invoke --
  191. #
  192. #    The user has invoked the listbox by pressing either the <Returh>
  193. # key or double-clicking. Call the user-supplied -command function.
  194. #
  195. # For both -browsecmd and -command, it is the responsibility of the
  196. # user-supplied function to determine the current selection of the listbox
  197. proc tixScrolledListBox:Invoke {w} {
  198.     upvar #0 $w data
  199.  
  200.     if {$data(-command) != ""} {
  201.     set bind(specs) {%V}
  202.     set bind(%V) [$data(w:listbox) get \
  203.         [$data(w:listbox) nearest [tixEvent flag y]]]
  204.     tixEvalCmdBinding $w $data(-command) bind
  205.     }
  206. }
  207.  
  208. proc tixScrolledListBox:KeyInvoke {w} {
  209.     upvar #0 $w data
  210.  
  211.     if {$data(-command) != ""} {
  212.     set bind(specs) {%V}
  213.     set bind(%V) [$data(w:listbox) get active]
  214.     tixEvalCmdBinding $w $data(-command) bind
  215.     }
  216. }
  217.  
  218. #----------------------------------------------------------------------
  219. #
  220. #        option configs
  221. #----------------------------------------------------------------------
  222. proc tixScrolledListBox:config-takefocus {w value} {
  223.     upvar #0 $w data
  224.   
  225.     $data(w:listbox) config -takefocus $value
  226. }    
  227.  
  228.  
  229. #----------------------------------------------------------------------
  230. #
  231. #        Widget commands
  232. #----------------------------------------------------------------------
  233.  
  234.  
  235. #----------------------------------------------------------------------
  236. #
  237. #        Private Methods
  238. #----------------------------------------------------------------------
  239. proc tixScrolledListBox:XView {w first last} {
  240.     upvar #0 $w data
  241.  
  242.     set data(x-first) $first
  243.     set data(x-last) $last
  244.  
  245.     $data(w:hsb) set $first $last
  246.     tixWidgetDoWhenIdle tixScrolledWidget:Configure $w
  247.  
  248.  
  249. }
  250.  
  251. proc tixScrolledListBox:YView {w first last} {
  252.     upvar #0 $w data
  253.  
  254.     set data(y-first) $first
  255.     set data(y-last) $last
  256.  
  257.     $data(w:vsb) set $first $last
  258.     tixWidgetDoWhenIdle tixScrolledWidget:Configure $w
  259.  
  260.     # Somehow an update here must be used to advoid osscilation
  261.     #
  262.     update idletasks
  263. }
  264.  
  265. #
  266. #----------------------------------------------------------------------
  267. # virtual functions to query the client window's scroll requirement
  268. #----------------------------------------------------------------------
  269. proc tixScrolledListBox:GeometryInfo {w mW mH} {
  270.     upvar #0 $w data
  271.  
  272.     return [list \
  273.     [list $data(x-first) $data(x-last)]\
  274.     [list $data(y-first) $data(y-last)]]
  275. }
  276.  
  277. proc tixScrolledListBox:Configure {w} {
  278.     upvar #0 $w data
  279.  
  280.     tixWidgetDoWhenIdle tixScrolledListBox:TrickScrollbar $w
  281.  
  282.     if {$data(-anchor) == "e"} {
  283.     $data(w:listbox) xview 100000
  284.     }
  285. }
  286.  
  287. # This procedure is necessary because listbox does not call x,y scroll command
  288. # when its size is changed
  289. #
  290. proc tixScrolledListBox:TrickScrollbar {w} {
  291.     upvar #0 $w data
  292.  
  293.     if [$data(w:listbox) select include 0] {
  294.     set inc 1
  295.     } else {
  296.     set inc 0
  297.     }
  298.  
  299.     $data(w:listbox) select set 0
  300.     if {!$inc} {
  301.     $data(w:listbox) select clear 0
  302.     }
  303. }
  304.